package twilight.companion.client;

import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import twilight.companion.TwilightCompanion;
import twilight.companion.client.model.MiniYetiModel;
import twilight.companion.client.renderer.MiniYetiRenderer;
import twilight.companion.client.renderer.SummonSkullRenderer;
import twilight.companion.client.renderer.RotatingSnowBlockRenderer;
import twilight.companion.init.ModEntities;
import twilight.companion.init.ModItems;

@Mod.EventBusSubscriber(modid = TwilightCompanion.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientSetup {

    @SubscribeEvent
    public static void onClientSetup(FMLClientSetupEvent event) {
        event.enqueueWork(() -> {
            ItemProperties.register(ModItems.TWILIGHT_CONTRACT.get(),
                new ResourceLocation(TwilightCompanion.MOD_ID, "contract_type"), (stack, level, entity, seed) -> {
                    if (stack.hasTag() && stack.getTag().contains("contract_type")) {
                        String contractType = stack.getTag().getString("contract_type");
                        if ("mini_yeti".equals(contractType)) {
                            return 1.0F;
                        }
                    }
                    return 0.0F;
                });
        });
    }

    @SubscribeEvent
    public static void registerLayers(EntityRenderersEvent.RegisterLayerDefinitions event) {
        event.registerLayerDefinition(MiniYetiModel.LAYER_LOCATION, MiniYetiModel::createBodyLayer);
    }

    @SubscribeEvent
    public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
        event.registerEntityRenderer(ModEntities.MINI_YETI.get(), MiniYetiRenderer::new);
        event.registerEntityRenderer(ModEntities.SUMMON_SKULL.get(), SummonSkullRenderer::new);
        event.registerEntityRenderer(ModEntities.ROTATING_SNOW_BLOCK.get(), RotatingSnowBlockRenderer::new);
    }
}